<template>
  <el-autocomplete v-model="value" :fetch-suggestions="fetchSuggestions" class="wfull" clearable @select="onSelect">
    <template #default="{ item }">
      <div class="flex">
        <div class="font-size-16px">{{ item.value }}</div>
        <div class="ml5px font-size-14px color-blue">{{ item.label }}</div>
      </div>
    </template>
  </el-autocomplete>
</template>

<script lang="ts" setup>
  import { ref } from 'vue'
  import { ElAutocomplete } from 'element-plus'
  import { useFieldAuthStore } from '@/store'

  const fieldAuthStore = useFieldAuthStore()

  const value = ref('')

  const fetchSuggestions = async (queryString: string, cb: any) => cb(await fieldAuthStore.search(queryString))
  const onSelect = (item: {value: string, label: string}) => value.value = item.value
</script>
